package com.appservice.controller;

import com.vidyu.businesslayer.businessentities.UserInProject;
import com.vidyu.servicelayer.servicedataentitties.UserInProjectRO;
import com.vidyu.servicelayer.servicedataentitties.ProjectRO;
import com.vidyu.servicelayer.serviceinterface.ControllerServiceWrapper;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * Created by IntelliJ IDEA.
 * Session: eyalsa
 * Date: 06/03/12
 * Time: 16:11
 * Link Users To Agency
 */
@Controller
public class ProjectController {

    private static final Logger logger = Logger.getLogger(ProjectController.class);

    @Autowired
    ControllerServiceWrapper controllerServiceWrapperImpl;


    //POST  http://localhost:8081/vidyu/project/addProjectToEmployer
    @RequestMapping(value = "/vidyu/project/addProjectToEmployer",method = RequestMethod.POST)
    public @ResponseBody
    long addProjectToEmployer(@RequestBody ProjectRO projectRO) throws Exception {
        try {
            return controllerServiceWrapperImpl.addProjectToEmployer(projectRO);
           } catch (Exception e) {
            logger.fatal(e);
            throw e;
        }
    }

    //POST http://localhost:8081/vidyu/project/updateProject
    @RequestMapping(value = "/vidyu/project/updateProject",method = RequestMethod.POST)
    public @ResponseBody
    void updateProject(@RequestBody ProjectRO projectRO) throws Exception{
        try {
            controllerServiceWrapperImpl.updateProject(projectRO);
        } catch (Exception e) {
            logger.fatal(e);
            throw e;
        }
    }

    //POST http://localhost:8081/vidyu/project/contractorApplyToProject
    @RequestMapping(value = "/vidyu/project/contractorApplyToProject",method = RequestMethod.POST)
    public @ResponseBody
    long contractorApplyToProject(@RequestBody UserInProjectRO userInProjectRO) throws Exception{
        try {
            return controllerServiceWrapperImpl.contractorApplyToProject(userInProjectRO);
        } catch (Exception e) {
            logger.fatal(e);
            throw e;
        }
    }

    //POST http://localhost:8081/vidyu/project/updateUserInProject
    @RequestMapping(value = "/vidyu/project/updateUserInProject",method = RequestMethod.POST)
    public @ResponseBody
    void updateUserInProject(@RequestBody UserInProjectRO userInProjectRO) throws Exception{
        try {
            controllerServiceWrapperImpl.updateUserInProject(userInProjectRO);
        } catch (Exception e) {
            logger.fatal(e);
            throw e;
        }
    }

    //GET http://localhost:8081/vidyu/project/getContractorsInProjectByStatus/1/APPLY
    @RequestMapping(value = "/vidyu/project/getUsersInProjectByStatus/{projectId}/{status}",method = RequestMethod.GET)
    public @ResponseBody
    List<UserInProject> getUsersInProjectByStatus(@PathVariable long projectId, @PathVariable String status) throws Exception{
        try {
            return controllerServiceWrapperImpl.getUsersInProjectByStatus(projectId, status);
        } catch (Exception e) {
            logger.fatal(e);
            throw e;
        }
    }
}

